package hui.zhang.web.action.system;

import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hui.zhang.domain.system.Role;
import hui.zhang.service.system.RoleService;
import hui.zhang.utils.BaseAction;

/**
 * 角色管理
 * 
 * @author hui.zhang
 * @date 2017年12月30日 下午8:42:03
 */

@Controller
@ParentPackage("struts-default")
@Namespace("/")
@Scope("prototype")
@SuppressWarnings("all")
public class RoleAction extends BaseAction<Role> {

	@Autowired
	private RoleService roleService;

	@Action(value = "role_list")
	public String list() {
		List<Role> roles = roleService.findAll();
		toJsonAndResponse(roles);
		return NONE;
	}
	
	private String[] permissionIds;
	private String menuIds;
	public void setPermissionIds(String[] permissionIds) {
		this.permissionIds = permissionIds;
	}
	public void setMenuIds(String menuIds) {
		this.menuIds = menuIds;
	}

	@Action(value = "role_save", results = {
			@Result(name = "success", location = "/pages/system/role.html", type = "redirect") })
	public String save() {
		roleService.save(model, permissionIds, menuIds);
		return SUCCESS;
	}
}
